#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <math.h>
#include "vo-base.h"


void printhelp(void)
{
	printf("1--pring all register values.\n" );
	printf("2--write a register\n" );
	printf("3--read a register\n" );	
}

int main(int argc,char* argv[])
{
	int dev;
	unsigned long reg;
	unsigned long value;
	struct vo_base_reg vo;
	int para ;
	
	if (argc != 2) {
    	printf("usage :%s 1|2|3\n",argv[0]);
		printhelp();
		return 0;
	}
	
	dev = open("/dev/vo-base", O_RDONLY);
	if (dev <= 0) {
		printf("vo-base device open fail\n");
		exit(0);
	}

	para = atoi(argv[1]);
	switch(para)
	{
		case 1:	
			/* 
			 * read all register value . for example 
			 */
		
			
			break ;

		case 2:	/* write */
			printf("(write...)please input reg and reg-value:\n") ;
			scanf("%x %x",&reg,&value);			
			//printf("reg = 0x%x, value = 0x%x\n", reg, value);

			vo.reg = (unsigned long)reg;
			vo.value = (unsigned long)value;			
			ioctl(dev, VO_BASE_SET_SIGNLE_REG, &vo);
			//printf("reg = 0x%x, value = 0x%x\n", vo.reg, vo.value);
			
			vo.value = 0;
			ioctl(dev, VO_BASE_GET_SIGNLE_REG, &vo.value);
			printf("reg = 0x%x, value = 0x%x\n", vo.reg, vo.value);
			break ;
		
		case 3:	/* read */
			printf("(read...)please input reg:\n") ;
			scanf("%x",&reg);	
			//printf("reg = 0x%x\n", reg);
			
			vo.reg = (unsigned long)reg;
			vo.value = vo.reg;	
			ioctl(dev, VO_BASE_GET_SIGNLE_REG, &vo.value);
			printf("reg = 0x%x, value = 0x%x\n", vo.reg, vo.value);			
			break ;
		
		default :
			break ;
	}

	close(dev);

	return 0;
}
